using System;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Threading;

namespace ExceptionViews.Client
{
	[Serializable]
	public sealed class ACustomException : Exception
	{
		private string appDomainName;
		private int processId;
		private int threadId;

		[SecurityPermission(SecurityAction.LinkDemand, Unrestricted = true)]
		private void Initialize()
		{
			this.threadId = Thread.CurrentThread.ManagedThreadId;
			this.processId = Process.GetCurrentProcess().Id;
			this.appDomainName = AppDomain.CurrentDomain.FriendlyName;
		}

		[SecurityPermission(SecurityAction.LinkDemand, Unrestricted = true)]
		public ACustomException()
			: base()
		{
			this.Initialize();
		}

		[SecurityPermission(SecurityAction.LinkDemand, Unrestricted = true)]
		public ACustomException(string message)
			: base(message)
		{
			this.Initialize();
		}

		[SecurityPermission(SecurityAction.LinkDemand, Unrestricted = true)]
		public ACustomException(string message, Exception innerEx)
			: base(message, innerEx)
		{
			this.Initialize();
		}

		[SecurityPermission(SecurityAction.LinkDemand, Unrestricted = true)]
		private ACustomException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			this.Initialize();
		}

		[SecurityPermission(SecurityAction.LinkDemand,
			Flags = SecurityPermissionFlag.SerializationFormatter)]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}
		
		public string AppDomainName
		{
			get
			{
				return this.appDomainName;
			}
		}

		public int ProcessId
		{
			get
			{
				return this.processId;
			}
		}

		public int ThreadId
		{
			get
			{
				return this.threadId;
			}
		}
	}
}
